#include<stdio.h>
#include<mysql/mysql.h>
#include<string.h>
void insert_3(MYSQL *mysql)
{
    char mysql_insert[100];
    int stid,suid,source;
    MYSQL_RES * res=NULL;
    int rows;
    char query_str[100];
    int f;
    printf("请输入学生ID 课程ID 课程分数：");
    scanf("%d %d %d",&stid,&suid,&source); 
    sprintf(mysql_insert,"insert into stusub (stid,suid,source) values ('%d','%d','%d')",stid,suid,source);
    snprintf(query_str,100,"select * from stusub where stid = %d and suid = %d",stid,suid);
    f = mysql_real_query(mysql,query_str,strlen(query_str));
    if(f != 0)
    {
        printf("mysql_real_query():%s\n",mysql_error(mysql));
    }
    res = mysql_store_result(mysql);
    rows = mysql_num_rows(res);
    if(rows ==0 )
    {
        if(mysql_query(mysql,mysql_insert))
        {
            fprintf(stderr,"%s\n",mysql_error(mysql));
        }
        else
        {  
            printf("插入成功!\n");
        }
    }
    else
    {
        printf("插入失败\n");
    }
} 

